﻿using System;

namespace HalconDotNet
{
	/// <summary>
	///   The HALCON vector classes are intended to support the export of
	///   HDevelop code that uses vectors, and to pass vector arguments to
	///   procedures that use vector parameters. They are not intended to be
	///   used as generic container classes in user code. For this purpose,
	///   consider using standard container classes such as List&lt;T&gt;.
	/// </summary>
	// Token: 0x020000A0 RID: 160
	public class HTupleVector : HVector
	{
		/// <summary>
		///   Create empty vector of specified dimension. In case of dimension
		///   0 a leaf vector for an empty tuple is created
		/// </summary>
		// Token: 0x06002003 RID: 8195 RVA: 0x000BB0DF File Offset: 0x000B92DF
		public HTupleVector(int dimension) : base(dimension)
		{
			this.mTuple = ((dimension <= 0) ? new HTuple() : null);
		}

		/// <summary>
		///   Create leaf vector of dimension 0 for the specified tuple
		/// </summary>
		// Token: 0x06002004 RID: 8196 RVA: 0x000BB0FA File Offset: 0x000B92FA
		public HTupleVector(HTuple tuple) : base(0)
		{
			if (tuple == null)
			{
				throw new HVectorAccessException("Null tuple not allowed in vector");
			}
			this.mTuple = new HTuple(tuple);
		}

		/// <summary>
		///   Create 1-dimensional vector by splitting input tuple into
		///   blocks of fixed size (except possibly for the last block).
		///   This corresponds to convert_tuple_to_vector_1d in HDevelop.
		/// </summary>
		// Token: 0x06002005 RID: 8197 RVA: 0x000BB120 File Offset: 0x000B9320
		public HTupleVector(HTuple tuple, int blockSize) : base(1)
		{
			if (blockSize <= 0)
			{
				throw new HVectorAccessException("Invalid block size in vector constructor");
			}
			int num = 0;
			while ((double)num < Math.Ceiling((double)tuple.Length / (double)blockSize))
			{
				int i = num * blockSize;
				int i2 = Math.Min((num + 1) * blockSize, tuple.Length) - 1;
				this[num] = new HTupleVector(tuple.TupleSelectRange(i, i2));
				num++;
			}
		}

		/// <summary>
		///   Create copy of tuple vector
		/// </summary>
		// Token: 0x06002006 RID: 8198 RVA: 0x000BB193 File Offset: 0x000B9393
		public HTupleVector(HTupleVector vector) : base(vector)
		{
			if (this.mDimension <= 0)
			{
				this.mTuple = new HTuple(vector.mTuple);
			}
		}

		// Token: 0x06002007 RID: 8199 RVA: 0x000BB1B6 File Offset: 0x000B93B6
		protected override HVector GetDefaultElement()
		{
			return new HTupleVector(this.mDimension - 1);
		}

		/// <summary>
		///   Access to the tuple value for leaf vectors (dimension 0)
		/// </summary>
		// Token: 0x170000A3 RID: 163
		// (get) Token: 0x06002008 RID: 8200 RVA: 0x000BB1C5 File Offset: 0x000B93C5
		// (set) Token: 0x06002009 RID: 8201 RVA: 0x000BB1D4 File Offset: 0x000B93D4
		public HTuple T
		{
			get
			{
				base.AssertDimension(0);
				return this.mTuple;
			}
			set
			{
				base.AssertDimension(0);
				if (value == null)
				{
					throw new HVectorAccessException("Null tuple not allowed in vector");
				}
				this.mTuple.Dispose();
				this.mTuple = new HTuple(value);
			}
		}

		/// <summary>
		///   Access to subvector at specified index. The vector will be
		///   enlarged to accomodate index, even in read access. The internal
		///   reference is returned to allow modifications of vector state. For
		///   read access, preferrably use the member function At(index).
		/// </summary>
		// Token: 0x170000A4 RID: 164
		public HTupleVector this[int index]
		{
			get
			{
				return (HTupleVector)base[index];
			}
			set
			{
				base[index] = value;
			}
		}

		/// <summary>
		///   Read access to subvector at specified index. An exception
		///   will be raised if index is out of range. The returned data
		///   is a copy and may be stored safely.
		/// </summary>
		// Token: 0x0600200C RID: 8204 RVA: 0x000BB21A File Offset: 0x000B941A
		public new HTupleVector At(int index)
		{
			return (HTupleVector)base.At(index);
		}

		// Token: 0x0600200D RID: 8205 RVA: 0x000BB228 File Offset: 0x000B9428
		protected override bool EqualsImpl(HVector vector)
		{
			if (this.mDimension >= 1)
			{
				return base.EqualsImpl(vector);
			}
			return ((HTupleVector)vector).T.TupleEqual(this.T);
		}

		/// <summary>
		///   Returns true if vector has same dimension, lengths, and elements
		/// </summary>
		// Token: 0x0600200E RID: 8206 RVA: 0x000BB256 File Offset: 0x000B9456
		public bool VectorEqual(HTupleVector vector)
		{
			return this.EqualsImpl(vector);
		}

		/// <summary>
		///   Concatenate two vectors, creating new vector
		/// </summary>
		// Token: 0x0600200F RID: 8207 RVA: 0x000BB25F File Offset: 0x000B945F
		public HTupleVector Concat(HTupleVector vector)
		{
			return (HTupleVector)base.ConcatImpl(vector, false, true);
		}

		/// <summary>
		///   Append vector to this vector
		/// </summary>
		// Token: 0x06002010 RID: 8208 RVA: 0x000BB26F File Offset: 0x000B946F
		public HTupleVector Append(HTupleVector vector)
		{
			return (HTupleVector)base.ConcatImpl(vector, true, true);
		}

		/// <summary>
		///   Insert vector at specified index
		/// </summary>
		// Token: 0x06002011 RID: 8209 RVA: 0x000BAF30 File Offset: 0x000B9130
		public HTupleVector Insert(int index, HTupleVector vector)
		{
			base.InsertImpl(index, vector, true);
			return this;
		}

		/// <summary>
		///   Remove element at specified index from this vector
		/// </summary>
		// Token: 0x06002012 RID: 8210 RVA: 0x000BAFBC File Offset: 0x000B91BC
		public new HTupleVector Remove(int index)
		{
			base.RemoveImpl(index);
			return this;
		}

		/// <summary>
		///   Remove all elements from this vector
		/// </summary>
		// Token: 0x06002013 RID: 8211 RVA: 0x000BB03C File Offset: 0x000B923C
		public new HTupleVector Clear()
		{
			this.ClearImpl();
			return this;
		}

		/// <summary>
		///    Create an independent copy of this vector
		/// </summary>
		// Token: 0x06002014 RID: 8212 RVA: 0x000BB27F File Offset: 0x000B947F
		public new HTupleVector Clone()
		{
			return (HTupleVector)this.CloneImpl();
		}

		// Token: 0x06002015 RID: 8213 RVA: 0x000BB28C File Offset: 0x000B948C
		protected override HVector CloneImpl()
		{
			return new HTupleVector(this);
		}

		// Token: 0x06002016 RID: 8214 RVA: 0x000BB294 File Offset: 0x000B9494
		protected override void DisposeLeafObject()
		{
			if (this.mDimension <= 0)
			{
				this.mTuple.Dispose();
			}
		}

		/// <summary>
		///   Concatenates all tuples stored in the vector
		/// </summary>
		// Token: 0x06002017 RID: 8215 RVA: 0x000BB2AC File Offset: 0x000B94AC
		public HTuple ConvertVectorToTuple()
		{
			if (this.mDimension > 0)
			{
				HTuple htuple = new HTuple();
				for (int i = 0; i < base.Length; i++)
				{
					htuple.Append(this[i].ConvertVectorToTuple());
				}
				return htuple;
			}
			return this.mTuple;
		}

		/// <summary>
		///   Provides a simple string representation of the vector,
		///   which is mainly useful for debug outputs.
		/// </summary>
		// Token: 0x06002018 RID: 8216 RVA: 0x000BB2F3 File Offset: 0x000B94F3
		public override string ToString()
		{
			if (this.mDimension <= 0)
			{
				return this.mTuple.ToString();
			}
			return base.ToString();
		}

		// Token: 0x0400118E RID: 4494
		private HTuple mTuple;
	}
}
